package com.iotek.ssm.controller;

import com.iotek.ssm.pojo.CustomQueryVo;
import com.iotek.ssm.pojo.SalaryDissent;
import com.iotek.ssm.service.SalaryDissentService;
import com.iotek.ssm.util.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/dissent")
public class SalaryDissentController {

    @Autowired
    private SalaryDissentService salaryDissentService;

    @Autowired
    private Util util;

    //添加异议
    @RequestMapping("/addDissent")
    public String addDissent(Model model, SalaryDissent salaryDissent) {
        try {
            salaryDissentService.addSalaryDissent(salaryDissent);
            util.setJumpDetails(model, "消息发布成功！", "返回首页！", "../user/userPageJump", 1);
        } catch (Exception e) {
            e.printStackTrace();
            util.setJumpDetails(model, "消息发布失败！", "返回首页！", "../user/userPageJump", 1);
        }
        return "jumpPage";
    }

    //获取异议列表
    @RequestMapping("/dissentList")
    @ResponseBody
    public List<SalaryDissent> dissentList(CustomQueryVo customQueryVo) {
        List<SalaryDissent> dissentList = null;
        try {
            dissentList = salaryDissentService.findSalaryDissent(customQueryVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dissentList;
    }

    //管理员处理异议消息
    @RequestMapping("/updateDissent")
    public String updateDissent(Model model, SalaryDissent salaryDissent) {
        try {
            salaryDissentService.updateSalaryDissent(salaryDissent);
            util.setJumpDetails(model, "处理成功！", "返回首页！", "../admin/managePageJump", 1);
        } catch (Exception e) {
            e.printStackTrace();
            util.setJumpDetails(model, "处理失败！", "返回首页！", "../admin/managePageJump", 1);
        }
        return "jumpPage";
    }

    //用户获取查看最近一次的异议消息
    @RequestMapping("/lastDissent")
    @ResponseBody
    public SalaryDissent lastDissent(CustomQueryVo customQueryVo) {
        SalaryDissent salaryDissent = null;
        try {
            salaryDissent = salaryDissentService.findLastDissent(customQueryVo);
            System.out.println("--------------------" + salaryDissent);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return salaryDissent;
    }
}
